package com.qst.servlet;

import com.alibaba.fastjson.JSON;
import com.qst.biz.RoleBiz;
import com.qst.biz.impl.RoleBizImpl;
import com.qst.entity.Role;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(
        name = "RoleGetAllServlet",
        urlPatterns = "/api/role/getAll"
)
public class RoleGetAllServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=UTF-8");
        RoleBiz roleBiz=new RoleBizImpl();
        List<Role> roleList = roleBiz.getAll();

        String content = JSON.toJSONString(roleList);
        System.out.println(content);
        PrintWriter out = resp.getWriter();

        out.write(content);
        out.flush();
        out.close();
    }
}
